Skip to content

fix(server): ban each put of an object outside AttachmentStorage.AddAsync - #541

Merged
pdevito3 merged 4 commits into
mainfrom
correct/object-put-owner
Nov 21, 2026
Merged

pdevito3 merged 4 commits into
mainfrom
correct/object-put-owner

Conversation

@pdevito3

Copy link
Copy Markdown
Owner

Why

Agents keep writing an object to storage around AttachmentStorage, so an object outlives its row or loses its row to the sweep (#413, #422, #519). The sweep keeps an object for Attachments:AddTimeout plus a margin, and only AttachmentStorage.AddAsync saves the row within that time. Before this change, nothing stopped a put on another path.

Closes #536

What changed

  • ObjectWriter now has the put. ObjectStorage.PutAsync is gone.
  • BannedSymbols.txt bans ObjectWriter and the Amazon.S3 namespace in the Server (RS0030). Each error names AttachmentStorage.AddAsync.
  • Four places suppress the ban: AttachmentStorage.AddAsync, each S3 member of ObjectStorage, ObjectWriter, and ObjectStorageRegistration.AddObjectStorage. BannedApiSuppressionTests pins their files.
  • docs/backend.md, attachments.md, and a new update note in template-updates.md now state the rule. The text "Put other files under another prefix" is gone, because the build now refuses that put.

Tradeoffs

  • Architecture alone does not work. C# has no access level that one other class can use. internal opens the put to the whole Server assembly. A separate project would also have to hold AttachmentStorage, which needs AppDbContext.
  • A type alone does not work either. A permit type with a constructor that only AttachmentStorage can call cannot be written. The outer class cannot call the private constructor of a nested type, and each factory that it can call is open to the whole assembly.
  • The ban is on the ObjectWriter type and not on the M: ID of the method, because an M: ID stops matching, with no warning, when the signature changes. The whole Amazon.S3 namespace is banned, so TransferUtility, CopyObjectAsync, multipart uploads, and a presigned PUT also fail.
  • Open (low): RS0030 does not see dynamic or reflection. It also does not flag a parameter or a DI type argument, but a put has to call a member, and each such call fails.

Blast Radius

The behavior does not change: the put is the same S3 call with the same token. An app built from the template fails to build at each put of its own outside AddAsync. The update note gives the steps.

Verification

Scratch handler, now removed: a bulk import that puts under tenants/ and saves its rows later.

ImportFiles.cs(15,15): error RS0030: The symbol 'ObjectWriter' is banned in this project: Put an object with AttachmentStorage.AddAsync, so that the sweep of the bucket keeps it until its row is saved.
ImportFiles.cs(16,15): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.

s3.PutObjectAsync, new TransferUtility(s3), a second put method in AttachmentStorage, and a PutAsync put back on ObjectStorage also fail with RS0030. The dotnet build FullstackTemplate.slnx run passes with 0 warnings. Unit tests: 2449/2449 pass. Integration: 590/590 pass. Functional: 507/507 pass. All 8 configs of the object-storage-lifecycle TLC check are at baseline. CI did not run because the Actions minutes are used up. The full proof output is in a PR comment.

…sync

The sweep of the bucket keeps an object only for Attachments:AddTimeout and a
margin, and only AttachmentStorage.AddAsync ends its put and the save of its row
within that time. A put on another path could lose its object to the sweep while
its row still names it (#536).

ObjectWriter now holds the put that ObjectStorage had. BannedSymbols.txt bans
ObjectWriter and the Amazon.S3 namespace in the Server (RS0030), and each error
names AttachmentStorage.AddAsync. AddAsync suppresses the ban for the put, and
the three storage files suppress it for the S3 client. BannedApiSuppressionTests
pins the four files.
A suppression on the whole class let a put added to ObjectStorage compile, and
each Server file could call it. Each S3 member now suppresses RS0030 on its own,
so a new member that calls S3 fails the build.

The update note in docs/template-updates.md gives the steps for an app whose
build fails at a put outside AttachmentStorage.AddAsync.
@pdevito3

Copy link
Copy Markdown
Owner Author

Proof that the ban fails on puts outside the owner. Each scratch change was built, then removed.

Scratch Domain/ScratchImports/ImportFiles.cs (writer.PutAsync, s3.PutObjectAsync, new TransferUtility(s3).UploadAsync), plus a second put method in AttachmentStorage:

FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(15,15): error RS0030: The symbol 'ObjectWriter' is banned in this project: Put an object with AttachmentStorage.AddAsync, so that the sweep of the bucket keeps it until its row is saved.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(16,15): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(16,33): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(16,56): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(16,78): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(16,89): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(17,30): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/ScratchImports/ImportFiles.cs(18,15): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Domain/Attachments/AttachmentStorage.cs(66,18): error RS0030: The symbol 'ObjectWriter' is banned in this project: Put an object with AttachmentStorage.AddAsync, so that the sweep of the bucket keeps it until its row is saved.

Scratch PutAsync put back on ObjectStorage, called from Domain/ScratchExports/ExportFiles.cs:

FullstackTemplate.Server/Resources/Storage/ObjectStorage.cs(13,18): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Resources/Storage/ObjectStorage.cs(13,36): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Resources/Storage/ObjectStorage.cs(13,59): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Resources/Storage/ObjectStorage.cs(13,84): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.
FullstackTemplate.Server/Resources/Storage/ObjectStorage.cs(13,95): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.

TLC (sh .agents/skills/object-storage-lifecycle/check.sh):

baseline  ObjectStorage: pass (904176 states)
baseline  Liveness: pass (127866 states)
baseline  Chart: pass (1480 states)
baseline  LateCommit: NoLiveRowWithoutObject (4117 states)
baseline  GraceNone: NoLiveRowWithoutObject (1796 states)
baseline  GraceLimit: NoLiveRowWithoutObject (1499 states)
baseline  SoftDeletedNames: liveness (1256 states)
baseline  DeletedTenantOrphan: NoObjectLeftInDeletedTenant (4632 states)
tlc exit 0

@pdevito3

Copy link
Copy Markdown
Owner Author

review-gate: passed 53cf2ca

Two rounds of pdstack:thermo-nuclear-review-subagent (opus). Round 1 found two medium findings: (M1) a class-level RS0030 suppression on ObjectStorage let a put added back to it compile, and (M2) there was no template update note. Both are fixed in 53cf2ca. Round 2 found no high or medium finding. Its two low wording findings are fixed in fde02c9.

One low finding stays open: RS0030 does not see dynamic or reflection calls. Normal code does not use them, and no analyzer of this repo checks them.

@pdevito3

Copy link
Copy Markdown
Owner Author

PASS+NOTES at head e360648 (base main 3b7a3c7). Independent verification in a detached worktree. I did not change the branch.

The build rule, as a developer meets it. I added a scratch file under Domain/ScratchImports/ with two handlers. One injects ObjectWriter and calls PutAsync. The other injects IAmazonS3 and calls PutObjectAsync. dotnet build FullstackTemplate.slnx failed (exit 1), and each error names AttachmentStorage.AddAsync:

ScratchImports.cs(10,18): error RS0030: The symbol 'ObjectWriter' is banned in this project: Put an object with AttachmentStorage.AddAsync, so that the sweep of the bucket keeps it until its row is saved.
ScratchImports.cs(16,18): error RS0030: The symbol 'Amazon.S3' is banned in this project: The S3 client goes around ObjectStorage and AttachmentStorage. Put an object with AttachmentStorage.AddAsync. List, delete, and sign with ObjectStorage.

(5 Amazon.S3 errors on line 16, one for each member and type of the call.) I also added a second method, SneakAsync, to AttachmentStorage that calls writer.PutAsync. It fails with the same ObjectWriter error at AttachmentStorage.cs(64,74), so the method-level suppression on AddAsync does not open the class. I removed the scratch code, and git status is clean.

Build and tests at e360648 (local, because CI has no minutes):

  • dotnet build FullstackTemplate.slnx: 0 warnings, 0 errors.
  • Unit: 2449/2449 pass. Integration: 590/590 pass. Functional: 507/507 pass.

The upload path in the running app. I used verify-fullstack-template with launch.sh (an --isolated stack, ZeroFactor, dev build) and the recipe recipes/examples/workshop-files.mjs. The recipe starts a tenant, adds a workshop, uploads a PNG and a PDF (201), shows the thumbnail from a signed URL, refuses the bad files (422), downloads the PDF with the same bytes, deletes it (204 and then 404 from storage), and reloads.

  • Base 3b7a3c7: PASSED, 17/17 steps.
  • Head e360648: PASSED 17/17 on the 2nd and 3rd runs. The 1st run failed one step. See note 1. The server had no Error logs.

Notes (no blocker):

  1. The recipe step "upload a PDF" compares the Download href with the downloadUrl of the POST answer. After the upload, the page loads the list again, and that list signs the URL again. When the new signature falls in the next second, the URLs differ only in X-Amz-Date (045252Z vs 045253Z) and X-Amz-Signature, and the step fails. This PR does not change the recipe or the signing, so I infer that base has the same flake. It is a fault of the recipe, not of the put.
  2. attachments.md dropped "Put other files under another prefix". But template-updates.md still tells an app to put a file that is not an attachment, such as an export, under another prefix with a suppression. The two docs can say the same thing.

@pdevito3
pdevito3 merged commit 93024f6 into main Nov 21, 2026
16 checks passed
@pdevito3
pdevito3 deleted the correct/object-put-owner branch November 21, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nothing stops a put under tenants/ outside AttachmentStorage.AddAsync, so the sweep can delete the object of a row saved later than the grace

1 participant